import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/components/Layout.vue'
import Header from '@/views/components/Header.vue'
import Main from '@/views/components/Main.vue'
import Home from '@/views/Home.vue'
import Login from '@/views/Login.vue'
import AdminList from '@/views/admin/AdminList.vue'
import EnterpriseList from '@/views/enterprise/EnterpriseList.vue'
import DepartmentList from '@/views/department/DepartmentList.vue'
import PositionList from '@/views/position/PositionList.vue'
import EmployeeList from '@/views/employee/EmployeeList.vue'
import EducationList from '@/views/education/EducationList.vue'
import WorkExperienceList from '@/views/workExperience/WorkExperienceList.vue'
import SkillCertificateList from '@/views/skillCertificate/SkillCertificateList.vue'
import TrainingRecordList from '@/views/trainingRecord/TrainingRecordList.vue'
import ContractList from '@/views/contract/ContractList.vue'
import AttendanceList from '@/views/attendance/AttendanceList.vue'
import SalaryList from '@/views/salary/SalaryList.vue'
import ChartList from '@/views/chart/ChartList.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '',
        components: {
          default: Main,
          header: Header
        },
        children: [
          {
            path: '/Home',
            name: 'Home',
            component: Home
          },
          {
            path: '/AdminList',
            name: 'AdminList',
            component: AdminList
          },
          {
            path: '/EnterpriseList',
            name: 'EnterpriseList',
            component: EnterpriseList
          },
          {
            path: '/DepartmentList',
            name: 'DepartmentList',
            component: DepartmentList
          },
          {
            path: '/PositionList',
            name: 'PositionList',
            component: PositionList
          },
          {
            path: '/EmployeeList',
            name: 'EmployeeList',
            component: EmployeeList
          },
          {
            path: '/EducationList',
            name: 'EducationList',
            component: EducationList
          },
          {
            path: '/WorkExperienceList',
            name: 'WorkExperienceList',
            component: WorkExperienceList
          },
          {
            path: '/SkillCertificateList',
            name: 'SkillCertificateList',
            component: SkillCertificateList
          },
          {
            path: '/TrainingRecordList',
            name: 'TrainingRecordList',
            component: TrainingRecordList
          },
          {
            path: '/ContractList',
            name: 'ContractList',
            component: ContractList
          },
          {
            path: '/AttendanceList',
            name: 'AttendanceList',
            component: AttendanceList
          },
          {
            path: '/SalaryList',
            name: 'SalaryList',
            component: SalaryList
          },
          {
            path: '/ChartList',
            name: 'ChartList',
            component: ChartList
          }
        ]
      }
    ]
  },
  {
    path: '/Login',
    name: 'Login',
    component: Login
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.name !== 'Login' && to.name !== 'VendorRegister' && !sessionStorage.getItem('backendToken')) {
    next('/Login')
  } else {
    next()
  }
})

export default router
